//#define __DEBUG__
// by Rommel
#define THIS_FILE "fn_getnearestbuilding.sqf"
#include "x_setup.sqf"

private ["_building", "_i", "_r","_pos","_res"];
//TYRGHEN NEARESTTAG
//_building = nearestBuilding _this;
_pos = _this;
if (typename _this == typename objNull) then { _pos = position _this };
_building = [["Building","House","BagBunker_base_F"],_pos,60] call FUNC(nearestObjType);

if (isNull _building) exitWith {[]};
_i = 0;
_r = -1;
while {str(_building buildingPos _i) != "[0,0,0]"} do {
	__INC(_i);
	__INC(_r);
};
if (_r == -1) exitWith {[]};
__TRACE_2("End","_building","_i")
[_building, _i]